package com.eastcode.base.view;

import com.eastcode.base.constants.Constants;

/**
 * SQL的视图封装
 * 
 * @author 王一进
 * 
 */
public class SqlView {

	/** 排序：升序，降序 **/
	private String ascDesc = "";

	/** SQL关键字 ORDER BY 字段 **/
	private String orderByKey;

	public String getOrderByKey() {
		return orderByKey;
	}

	/**
	 * 设置排序关键字
	 * 
	 * @param orderByKey
	 */
	public void setOrderByKey(String orderByKey) {
		this.orderByKey = orderByKey + getAscDesc();
	}

	/**
	 * 设置排序关键字（多个字段排序）
	 * 
	 * @param orderByKeys
	 */
	public void setOrderByKey(String[] orderByKeys) {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; orderByKeys != null && i < orderByKeys.length; i++) {
			sb.append(orderByKeys[i]);
			if (i != orderByKeys.length - 1) {
				sb.append(",");
			}
		}
		this.orderByKey = sb.toString() + getAscDesc();
	}

	public String getOrderBy() {
		if (this.orderByKey != null && this.orderByKey.length() > 0) {
			return Constants.SQL_ORDER_BY + this.orderByKey;
		} else {
			return "";
		}
	}

	public String getAscDesc() {
		return ascDesc;
	}

	/**
	 * 设置升序，降序
	 * 
	 * @param ascDesc
	 */
	public void setAscDesc(String ascDesc) {
		this.ascDesc = ascDesc;
	}

}